#include <cmath>

using namespace std;

#include "EasyBMP.h"
#include "ImprovedMath.h"
#include "Matrix.h"

Matrix BMPtoMatrix( BMP& Image, double Min, double Max )
{
 Matrix Output = zeros( Image.TellWidth(), Image.TellHeight() );

 double Scale = 255.0 * sqrt(3.0);
 
 int i,j;
 for( j=0; j < Output.TellCols() ; j++ )
 {
  for( i=0 ; i < Output.TellRows() ; i++ )
  {
   int J = Image.TellHeight()-1-j;
  
   double GrayValue = square( Image(i,J)->Red )
                    + square( Image(i,J)->Green )
					+ square( Image(i,J)->Blue );
   GrayValue = sqrt(GrayValue);					
  
   *Output(i,j) = Min + (Max-Min)*GrayValue/Scale;
  }
 }

 return Output;
}

Matrix BMPfileToMatrix( const char* FileName, double Min, double Max )
{ 
 BMP TemporaryImage;
 TemporaryImage.ReadFromFile( FileName );
 Matrix Output = BMPtoMatrix( TemporaryImage, Min, Max );
 return Output;
}
